<%@Page Language="VB"%>

<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.SqlClient" %>

<%@ Register TagPrefix="wrox" TagName="connect" Src="..\global\connect-strings.ascx" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Using Implicit Parameters in MS SQL Server</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">Using Implicit Parameters in MS SQL Server</span><hr />
<!--------------------------------------------------------------------------->

<%'-- insert connection string script --%>
<wrox:connect id="ctlConnectStrings" runat="server"/>

<div>Connection string: <b><span id="outConnect" runat="server"></span></b></div>
<div>Command Text: <b><span id="outCommandText" runat="server"></span></b></div>
<div id="outError" runat="server">&nbsp;</div>

<asp:datagrid id="dgrResult" runat="server" />

<script language="vb" runat="server">

Sub Page_Load()

   'get connection string from ..\global\connect-strings.ascx user control
   Dim strConnect = ctlConnectStrings.SQLConnectionString
   outConnect.InnerText = strConnect 'and display it

   'create the SQL statement that will call the stored procedure
   'and provide the single parameter for the ISBN to match
   'note that this syntax only works with the 'SQL' objects
   Dim strCommandText As String = "FindFromTitleAndDate '%Professional%', '02/01/2000'"
   outCommandText.InnerText = strCommandText 'and display it

   'create a new Connection object using the connection string
   Dim objConnect As New SqlConnection(strConnect)

   'create a new Command using the CommandText and Connection object
   Dim objCommand As New SqlCommand(strCommandText, objConnect)

   'declare a variable to hold a DataReader object
   Dim objDataReader As SqlDataReader

   Try

      'open the connection and execute the command
      objConnect.Open()
      objDataReader = objCommand.ExecuteReader()

   Catch objError As Exception

      'display error details
      outError.innerHTML = "<b>* Error while accessing data</b>.<br />" _
          & objError.Message & "<br />" & objError.Source
      Exit Sub  ' and stop execution

   End Try

   'assign the DataReader object to the DataGrid control
   dgrResult.DataSource = objDataReader
   dgrResult.DataBind()  'and bind (display) the data

End Sub
</script>


<!--------------------------------------------------------------------------->
<!-- #include file="..\global\foot.inc" -->
</body>
</html>
